-
Notifications
You must be signed in to change notification settings - Fork 113
feat: Add CEL expression evaluator command #2151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Add CEL expression evaluator command #2151
Conversation
/jira |
💫 Jira ticket created: SRVKP-8026 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new tkn pac cel
command, providing an interactive and non-interactive REPL for evaluating CEL expressions against real webhook payloads and HTTP headers.
- Introduces the
cel
subcommand in the CLI root. - Implements provider detection, event parsing, and an interactive readline-based REPL.
- Adds comprehensive tests and updates documentation.
Reviewed Changes
Copilot reviewed 7 out of 41 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
pkg/cmd/tknpac/root.go | Register the new cel command under tkn pac |
pkg/cmd/tknpac/cel/templates/help.tmpl | Create help template with available variables & examples |
pkg/cmd/tknpac/cel/cel.go | Implement cel command logic, provider detection, REPL |
pkg/cmd/tknpac/cel/cel_test.go | Add extensive unit tests covering parsing, evaluation, providers, flags, files |
pkg/cel/cel.go | Extend CEL environment to include direct variables |
docs/content/docs/guide/cli.md | Document usage for tkn pac cel |
go.mod | Add github.com/chzyer/readline dependency |
Comments suppressed due to low confidence (2)
docs/content/docs/guide/cli.md:425
- [nitpick] The example headers block includes
Request method: POST
, which is not a standard HTTP header and will be treated as a custom key by the parser. Consider removing or clarifying this line.
Request method: POST
pkg/cel/cel.go:55
- [nitpick] The body is marshaled then unmarshaled to a map for CEL. If
body
is already a map or structured data, avoid the double marshal/unmarshal by type asserting or converting directly.
decls.NewVariable("headers", mapStrDyn),
🤖 AI Review provided by gemini:gemini-2.5-pro:Excellent! This is a substantial and well-thought-out feature commit. It adds a powerful new Here is a careful analysis of the changes, highlighting potential bugs, spelling mistakes, and code improvements. Summary of AnalysisOverall, this is a high-quality commit. The core logic is solid, and the feature is well-implemented with good test coverage. The identified issues are relatively minor and easy to address.
🐛 Bugs & Potential IssuesThese are items that could cause incorrect behavior under certain conditions.
📝 Spelling and DocumentationThese are minor typos and clarifications in comments and documentation.
💡 Code Improvements & Idiomatic GoThese are suggestions to make the code cleaner, more robust, or more idiomatic.
Final VerdictThis is an excellent commit that adds a very useful feature. The implementation is robust, especially with the fallback from |
/retest |
/lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congrats @chmouel your PR Has been approved 🎉
✅ Pull Request Approved
Approval Status:
- Required Approvals: 1
- Current Approvals: 1
👥 Reviewers Who Approved:
Reviewer | Permission Level | Approval Status |
---|---|---|
@zakisk | admin |
✅ |
📝 Next Steps
- Ensure all required checks pass
- Comply with branch protection rules
- Request a maintainer to merge using the
/merge
command (or merge it
directly if you have repository permission).
Automated by the PAC Boussole 🧭
/retest |
17052ff
to
e3c0d9c
Compare
This commit introduces a new command `tkn pac cel` that allows users to interactively evaluate CEL (Common Expression Language) expressions. The command is designed to help users test and debug CEL expressions, which are commonly used in Pipelines-as-Code. Key features include: - Interactive and non-interactive modes. - Support for webhook payloads and headers. - Provider auto-detection (GitHub, GitLab, Bitbucket Cloud, Bitbucket Data Center, Gitea). - Direct access to variables as per PAC documentation. - Cross-platform history with readline experience. - Comprehensive help and example expressions. Signed-off-by: Chmouel Boudjnah <[email protected]> feat: Support gosmee-generated shell scripts for headers - Allow the CLI to parse headers from gosmee scripts. - Add support for JSON, plain text and gosmee scripts header formats. - Update documentation to reflect the changes in the header file formats. - Add tests to validate the script and header parsing. Signed-off-by: Chmouel Boudjnah <[email protected]>
e3c0d9c
to
e7347b5
Compare
it is LGTM, do I merge or you wanna make more changes? |
@zakisk i think wait for it, there is some edge case that makes it buggy compared to live event... i'll let you know if we keep it "as is" |
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new tkn pac cel
command, which is a powerful tool for interactively evaluating CEL expressions. The implementation is comprehensive, covering multiple Git providers, different payload formats, and both interactive and non-interactive modes. The code is well-structured, and the addition of tests and documentation is excellent.
My review includes a few suggestions to improve maintainability and correct the output stream for error messages. Overall, this is a great feature addition.
|
||
val, err := pkgcel.Value(expr, body, headers, pacParams, filesData) | ||
if err != nil { | ||
fmt.Fprintln(ioStreams.Out, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errors from CEL evaluation should be printed to stderr
instead of stdout
. This is standard practice for CLI tools and allows users to redirect successful output without capturing error messages. This issue is present in all three expression evaluation loops (interactive, survey fallback, and non-interactive).
fmt.Fprintln(ioStreams.Out, err) | |
fmt.Fprintln(ioStreams.ErrOut, err) |
// Parse the GitHub webhook to get the typed event | ||
ghEvent, err := github.ParseWebHook(event.EventType, body) | ||
if err != nil { | ||
return event, nil // nolint: nilerr // fallback to basic parsing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In eventFromGitHubWithProvider
, errors during API calls for data enrichment are currently suppressed to provide a fallback to basic parsing. While this makes the tool resilient, it hides potential issues from the user (e.g., an invalid token, network issues). Consider passing ioStreams
to this function to log a warning to stderr
when an error occurs, informing the user that the event data is incomplete. This would provide better feedback to the user about why some data might be missing.
} | ||
} | ||
// nolint:ineffassign,staticcheck | ||
pacParams := map[string]string{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pacParams
variable is initialized with an empty map, but its value is never used as it's immediately overwritten inside the switch
statement on the following lines. To make the code more efficient and cleaner, you can declare it without initialization.
pacParams := map[string]string{} | |
var pacParams map[string]string |
// Create files data structure (always empty in CLI mode) | ||
filesData := map[string]any{ | ||
"all": []string{}, | ||
"added": []string{}, | ||
"deleted": []string{}, | ||
"modified": []string{}, | ||
"renamed": []string{}, | ||
} | ||
|
||
val, err := pkgcel.Value(expr, body, headers, pacParams, filesData) | ||
if err != nil { | ||
fmt.Fprintln(ioStreams.Out, err) | ||
} else { | ||
fmt.Fprintf(ioStreams.Out, "%v\n", val) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"event": pacParams["event"], | ||
"target_branch": pacParams["target_branch"], | ||
"source_branch": pacParams["source_branch"], | ||
"target_url": pacParams["target_url"], | ||
"source_url": pacParams["source_url"], | ||
"event_title": pacParams["event_title"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string keys for pacParams
(e.g., "event"
, "target_branch"
) are hardcoded here and in pkg/cmd/tknpac/cel/cel.go
where these parameters are populated. This is fragile and error-prone. To improve maintainability, these keys should be defined as exported constants in a shared package (e.g., pkg/params/info
) and used in both places.
Changes
This commit introduces a new command
tkn pac cel
that allows users to interactively evaluate CEL (Common Expression Language) expressions. The command is designed to help users test and debug CEL expressions, which are commonly used in Pipelines-as-Code.Screen.Recording.2025-06-30.at.11.mp4
Key features include:
JIRA: https://issues.redhat.com/browse/SRVKP-8026
Submitter Checklist
📝 Ensure your commit message is clear and informative. Refer to the How to write a git commit message guide. Include the commit message in the PR body rather than linking to an external site (e.g., Jira ticket).
♽ Run make test lint before submitting a PR to avoid unnecessary CI processing. Consider installing pre-commit and running pre-commit install in the repository root for an efficient workflow.
✨ We use linters to maintain clean and consistent code. Run make lint before submitting a PR. Some linters offer a --fix mode, executable with make fix-linters (ensure markdownlint and golangci-lint are installed).
📖 Document any user-facing features or changes in behavior.
🧪 While 100% coverage isn't required, we encourage unit tests for code changes where possible.
🎁 If feasible, add an end-to-end test. See README for details.
🔎 Address any CI test flakiness before merging, or provide a valid reason to bypass it (e.g., token rate limitations).
If adding a provider feature, fill in the following details:
(update the provider documentation accordingly)